﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
namespace WPFExcelReport
{
    public partial class TWBBEW
    {
        #region ==dwWS===========
        public static readonly DependencyProperty dwWSProperty = DependencyProperty.Register("dwWS",
            typeof(DataRow), typeof(TWBBEW),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwWSChanged));
        public DataRow dwWS
        {
            get
            {
                return (DataRow)GetValue(dwWSProperty);
            }
            set
            {
                SetValue(dwWSProperty, value);
            }
        }
        private static void OndwWSChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TWBBEW;
            if (src != null)
            {
                src.dwWS = (DataRow)e.NewValue;
            }
        }
        #endregion
        #region ==dwWB===========
        public static readonly DependencyProperty dwWBProperty = DependencyProperty.Register("dwWB",
            typeof(DataRow), typeof(TWBBEW),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwWBChanged));
        public DataRow dwWB
        {
            get
            {
                return (DataRow)GetValue(dwWBProperty);
            }
            set
            {
                SetValue(dwWBProperty, value);
            }
        }
        private static void OndwWBChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TWBBEW;
            if (src != null)
            {
                src.dwWB = (DataRow)e.NewValue;
            }
        }
        #endregion
     
        #region ==WBEWBS===========
        public static readonly DependencyProperty WBEWBSProperty = DependencyProperty.Register("WBEWBS",
            typeof(string), typeof(TWBBEW),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWBEWBSChanged));
        public string WBEWBS
        {
            get
            {
                return (string)GetValue(WBEWBSProperty);
            }
            set
            {
                SetValue(WBEWBSProperty, value);
            }
        }
        private static void OnWBEWBSChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TWBBEW;
            if (src != null)
            {
                src.WBEWBS = (string)e.NewValue;
            }
        }
        #endregion
        #region ==WBEWBELEG===========
        public static readonly DependencyProperty WBEWBELEGProperty = DependencyProperty.Register("WBEWBELEG",
            typeof(string), typeof(TWBBEW),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWBEWBELEGChanged));
        public string WBEWBELEG
        {
            get
            {
                return (string)GetValue(WBEWBELEGProperty);
            }
            set
            {
                SetValue(WBEWBELEGProperty, value);
            }
        }
        private static void OnWBEWBELEGChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TWBBEW;
            if (src != null)
            {
                src.WBEWBELEG = (string)e.NewValue;
            }
        }
        #endregion
        public static readonly TWBBEW Instance = new TWBBEW();
        public TWBBEW()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VWBBEW();
            this.DataContext = MV;
            InitializeComponent();
        }
        
        
        int WBEWLFDNR = 1;
        string LastOrder = "";
        public override void New()
        {
            ((VWBBEW)MV).NWBBEW(dwWB, WBEWBS, RUNID);
        }
        private void Insert(DataRow _dwWB14)
        {
            ((VWBBEW)MV).InsertWBBEW(_dwWB14, app.company);
         }
        public string GetLastBELEG(string _termno)
        {
            string beleg = "0";
            dwData = TBMain.NewRow();
            dwData["WBEWMANDANT"] = app.Mandant;
            dwData["WBEWFC"] = "QI04    ";
            dwData["WBEWMLFDNR"] = "0801";
            dwData["WBEWMPOS"] = "01";
            SResult = ((VWBBEW)MV).QueryWBBEW(dwData, 8);
            foreach (DataRow row in SResult.Tables[0].Rows)
            {
                beleg = row["WBEWBELEG"].ToString();
            }
            return beleg;
        }
    }
}
